import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import Components from "unplugin-vue-components/vite";
import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
//插件引入
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import path from "path";
import WindiCSS from "vite-plugin-windicss";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    WindiCSS(),
    Components({
      resolvers: [AntDesignVueResolver()],
    }),
    createSvgIconsPlugin({
      // 指定需要缓存的图标文件夹
      iconDirs: [path.resolve(process.cwd(), "src/icons")],
      // 指定symbolId格式
      symbolId: "icon-[dir]-[name]",
    }),
  ],
  resolve: {
    alias: [
      // Resolve tsconfig paths
      { find: "@", replacement: "/src" },
      // Trim leading tilde in less files
      { find: /^~/, replacement: "" },
    ],
  },
  server: {
    host: "0.0.0.0",
    port: 9090,
    open: true, // 是否自动在浏览器打开
    proxy: {
      "/admin": {
        // target: "https://shop-api.chuangfu668.com", // 正式
        target: "http://test-shop-api.chuangfu668.com", // 测试
        // target: "http://test-draw-api.sjd1888.com",
        changeOrigin: true, // 是否跨域
        pathRewrite: {
          "^/admin": "",
        },
      },
    },
  },
});
